package com.by.service.sys.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.by.common.crud.BaseServiceImpl;
import com.by.entity.sys.Menu;
import com.by.mapper.sys.MenuMapper;
import com.by.service.sys.MenuService;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MenuServiceImpl extends BaseServiceImpl<MenuMapper, Menu> implements MenuService {

    @Override
    public List queryMenuTree() {
        return baseMapper.queryMenuTree();
    }

    @Override
    public List queryChild(String pid) {
        return baseMapper.queryChild(pid);
    }

    @Override
    public int delete(Serializable id) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("parentid", id);
        long count = baseMapper.selectCount(wrapper);
        if (count > 0)
            return 2;
        return super.delete(id);
    }


    @Override
    public Map queryAuths(String roleId) {

        //根据角色查询导航
        List list = baseMapper.queryNavMenus(roleId);
        //根据角色查询授权字符串
        String auths = baseMapper.queryAuths(roleId);
        Map map = new HashMap();
        map.put("menus", list);
        map.put("auths", auths);
        return map;
    }
}
